﻿namespace PrimeNumber
{/// <summary>
/// 找最大质数
/// </summary>
    internal class Program
    {
        
        static void Main(string[] args)
        {//自定义输入整数
           Console.WriteLine("请输入一个数:");
            int n = Convert.ToInt32(Console.ReadLine());
            int PrimeNum = 1;
            //开始计时
            DateTime StartTime = DateTime.Now;
            for (int i = 2; i <= n; i++)
            {
                
                for (int j = 2; j <= i; j++)
                {
                    if (i % j == 0)
                    {
                        if (j == i)
                            PrimeNum = i;
                        else break;
                    }
                }
               
     
            }
            Console.WriteLine("最大的质数为{0}", PrimeNum);
            //计时结束
            DateTime EndTime = DateTime.Now;
            TimeSpan totaltime = EndTime - StartTime;
            Console.WriteLine("总用时为{0}", totaltime);
            Console.ReadKey();

        }
        
    }


}

